/*
 * Method.cpp
 *
 *  Created on: Aug 5, 2009
 *      Author: ramesh
 */

#include "Method.h"

#include "../AST.h"

using namespace SymphonyAST;


void Method::addParameter(string par) {
	trim(par);

	if (par.length() == 0) {
		return;
	}

	vector<string> tokens;
	split(tokens, par, is_any_of(" "), token_compress_on);

	Variable* var = new Variable;

	for (int i = 0; i < (int)(tokens.size()) - 2;i++){
        var->addProperty(tokens[i]);
    }
    string typeToken = tokens[tokens.size() - 2];
    int type = getContainingClass(this)->getImportedId(typeToken);
    if(type > 0) {
		parametersTypes.push_back(type);
		var->setType(type);
	} else {
		throw "unexpected word " + typeToken + ".";
	}

	string varName = tokens[tokens.size()-1];
	addVariable(varName, var);
}


string Method::getName() {
	return name;
}

void Method::setName(const string& name) {
	this->name = name;
}


int Method::getReturnTypeId() {
	return ((Class*)parent)->getImportedId(returnType);
}

void Method::setReturnType(const string& returnType) {
	this->returnType = returnType;
}


vector<int> Method::getParametersTypes() {
	return parametersTypes;
}
